# -*- coding : utf_8 -*-
"""
=======================================
Time : 2025/4/12 22:29
Author : 田霄汉
Email : 522989570@qq.com
File : matplotlib_class10.py
Project : pandas_demo
Function : 饼状图
=======================================
"""

import pandas as pd
import matplotlib.pyplot as plt
from config.setting import file_path

excel10_path = file_path['excel_path']+'/excel10.xlsx'
products = pd.read_excel(io=excel10_path,
                         skiprows=3,
                         usecols='C:H',
                         index_col='BOOK_NUM')
# ascending=True表示从小到大排序
products.sort_values(by='2023', inplace=True, ascending=True)
# 想让饼图顺时针排列就使用counterclock=False
products['2023'].plot.pie(fontsize=8, counterclock=False)
plt.title(label='BOOKS PIE by 2023', fontsize=16, fontweight='bold')
plt.ylabel(ylabel='2023', fontsize=12, fontweight='bold')
# 设置label与图标的距离
plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
plt.tight_layout()
plt.show()
